package shop;

import goods.GoodAttributes;
import goods.GoodItem;

import java.util.ArrayList;
import java.util.List;

public class Mall {
	static int ID = 1;
	public static ShoppingCart cart = new ShoppingCart();
	
	private List<GoodAttributes> commodities= new ArrayList<>();
	{
		commodities.add(new GoodAttributes("realme 真我Q3 Pro手机", 1799.0, ID++, "phone"));
		commodities.add(new GoodAttributes("realme 真我GT 大师探索版手机", 3199.0, ID++, "phone"));
		commodities.add(new GoodAttributes("巴利 男士黑色银色扣头牛皮板扣式双面皮带腰带", 1599.0, ID++, "cloth"));
		commodities.add(new GoodAttributes("范思哲Versace Jeans Couture奢侈品男装", 649.0, ID++, "cloth"));
		commodities.add(new GoodAttributes("骆驼（CAMEL）马丁女靴英伦风沙漠网红靴短靴高帮靴工装靴子", 79.0, ID++, "shoes"));
		commodities.add(new GoodAttributes("华为P40 Pro 5G手机", 6958.0, ID++, "phone"));
		commodities.add(new GoodAttributes("索泰RTX3070ti", 11998.0, ID++, "computer"));
		commodities.add(new GoodAttributes("联想(Lenovo)拯救者R9000P", 8999.0, ID++, "computer"));
		commodities.add(new GoodAttributes("ECCO爱步男士休闲鞋", 2199.0, ID++, "shoes"));
	}
	
	//展示初始商品列表
	public void showGoods()
	{
		System.out.println("**********************商城的商品*************************");
		for(int i = 0; i <commodities.size();i++) {
			System.out.println(commodities.get(i).toString());
		}
		System.out.println("*******************************************************");
	}
	
	//查询商品关键字并打开商品属性
	public void searchWord(String s)
	{
		System.out.println("****************查询到的商品有：*******************");
		for(int i = 0; i <commodities.size();i++) {
			if(commodities.get(i).getName().indexOf(s) >= 0)
			{
				System.out.println(commodities.get(i).toString());
			}
		}
		System.out.println("************************************************");
	}
	
	//查询商品类型并打开商品属性
	public void searchType(String s)
	{
		System.out.println("****************查询到的商品有：*******************");
		for(int i = 0; i <commodities.size();i++) {
			if(commodities.get(i).getType().indexOf(s) >= 0)
			{
				System.out.println(commodities.get(i).toString());
			}
		}
		System.out.println("************************************************");
	}
	
	//加入购物车
	public int putinCart(int id)
	{
		int flag = 0;
		GoodItem one = null;
		for(int i = 0; i < cart.item.size(); i++) {//查询是否已经存在
			if(cart.item.get(i).getId()==id)
			{
				flag = 1;
				cart.item.get(i).setNum(cart.item.get(i).getNum()+1);
				break;
			}
		}
		
		if(flag != 1)
			for(int i = 0; i <commodities.size();i++) {
				if(commodities.get(i).getId()==id)
				{
					one = new GoodItem(commodities.get(i).getName(),commodities.get(i).getPrice() , id, commodities.get(i).getType(),1);
					flag = 2;
					break;	
				}
			}
		
		
		if (flag == 2)
			cart.item.add(one);
		
		
		return flag;
	}
	
}
